package com.zpark.controller;

import com.zpark.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;


@RestController
@Slf4j
@RequestMapping("/user")
public class UserController {
    @PostMapping(path = "/check")
    public String check(@RequestBody @Valid User user, BindingResult result) {
        String name = user.getName();
        if (result.hasErrors()) {
            List<ObjectError> list = result.getAllErrors();
            for (ObjectError error : list) {
                System.out.println(error.getCode() + "_" + error.getDefaultMessage());
            }
        }
        return name;
    }
}
